Completed
Branch master (ce2c9c)
by Jesus
04:32
created

$(document).turbolinks:load   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 59
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
dl 0
loc 59
rs 8.6453
c 2
b 0
f 0
eloc 32
nc 4
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
2
//
3
// Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
4
//
5
// This program is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU Lesser General Public License as published by the Free Software
7
// Foundation; either version 3.0 of the License, or (at your option) any later
8
// version.
9
//
10
// BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
11
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
// PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
13
//
14
// You should have received a copy of the GNU Lesser General Public License along
15
// with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
16
17
$(document).on('turbolinks:load', function(){
18
  var controller = $("body").data('controller');
19
  var action = $("body").data('action');
20
21
  // Only run on the admins page.
22
  if (controller == "admins" && action == "index") {
23
    // show the modal with the correct form action url
24
    $(".delete-user").click(function(data){
25
      var uid = $(data.target).closest("tr").data("user-uid")
26
      var url = $("body").data("relative-root")
27
      if (!url.endsWith("/")) {
28
        url += "/"
29
      }
30
      url += "u/" + uid
31
      $("#delete-confirm").parent().attr("action", url)
32
    })
33
34
    //clear the role filter if user clicks on the x
35
    $(".clear-role").click(function() {
36
      var search = new URL(location.href).searchParams.get('search')
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
37
38
      var url = window.location.pathname + "?page=1"
39
    
40
      if (search) {
41
        url += "&search=" + search
42
      }  
43
    
44
      window.location.replace(url);
45
    })
46
    
47
    /* COLOR SELECTORS */
48
    
49
    $('#colorinput-regular').ColorPicker({
50
      onBeforeShow: function () {
51
        var colour = rgb2hex($("#colorinput-regular").css("background-color"))
52
53
        $(this).ColorPickerSetColor(colour);
54
      },
55
      onSubmit: function(_hsb, hex) {
56
        $.post($("#coloring-path-regular").val(), {color: '#' + hex}).done(function() {
57
          location.reload()
58
        });
59
      },
60
    });
61
62
    $('#colorinput-lighten').ColorPicker({
63
      onBeforeShow: function () {
64
        var colour = rgb2hex($("#colorinput-lighten").css("background-color"))
65
66
        $(this).ColorPickerSetColor(colour);
67
      },
68
      onSubmit: function(_hsb, hex) {
69
        $.post($("#coloring-path-lighten").val(), {color: '#' + hex}).done(function() {
70
          location.reload()
71
        });
72
      },
73
    });
74
75
    $('#colorinput-darken').ColorPicker({
76
      onBeforeShow: function () {
77
        var colour = rgb2hex($("#colorinput-darken").css("background-color"))
78
79
        $(this).ColorPickerSetColor(colour);
80
      },
81
      onSubmit: function(_hsb, hex) {
82
        $.post($("#coloring-path-darken").val(), {color: '#' + hex}).done(function() {
83
          location.reload()
84
        });
85
      },
86
    });
87
  }
88
89
  // Only run on the admins edit user page.
90
  if (controller == "admins" && action == "edit_user") {
91
    $(".setting-btn").click(function(data){
92
      var url = $("body").data("relative-root")
93
      if (!url.endsWith("/")) {
94
        url += "/"
95
      }
96
      url += "admins?setting=" + data.target.id
97
98
      window.location.href = url
99
    })
100
  }
101
});
102
103
// Change the branding image to the image provided
104
function changeBrandingImage(path) {
105
  var url = $("#branding-url").val()
106
  $.post(path, {url: url})
107
}
108
109
// Filters by role
110
function filterRole(role) {
111
  var search = new URL(location.href).searchParams.get('search')
0 ignored issues
show
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
112
113
  var url = window.location.pathname + "?page=1" + "&role=" + role
114
115
  if (search) {
116
    url += "&search=" + search
117
  }  
118
119
  window.location.replace(url);
120
}
121
122
function rgb2hex(rgb) {
123
  rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
124
  function hex(x) {
125
      return ("0" + parseInt(x).toString(16)).slice(-2);
126
  }
127
  return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
128
}
129
130